var app = getApp();
Page(Object.assign({}, {
    data:{
        inited : false,
        form : {},
        showqun : false,
        geted : 0,
		siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
    },
    onLoad:function(options){
        var self = this;

        app.com.auth(function(user){
            app.com.http('admin','POST',{op:'drawinit',frm:'jifenadd'},0,false,'','',function(res){
                if (!res.data.errno) {
                    self.setData({
                        Pagetheme : res.data.data.params.style,
                        params : res.data.data.params,
                    },function(){
                        self.setData({
                            inited : true,
                        });
						
						wx.setNavigationBarTitle({
							title:  '充值'+self.data.params.jfbname,
						});
                    });
                    // 关闭下拉刷新
                    wx.stopPullDownRefresh();
                }else{
                    app.com.alert(res.data.message);
                }
            });
        },self);
    },
    onShareAppMessage : function(){
        var self = this;
        return {
            title: self.data.sharedata.title,
            path: '',
        }
    },
    addthis : function(e){
        this.setData({
            money : e.currentTarget.dataset.m
        })
    },
    confirm(e){
        var self = this;
        
        if( self.data.money*1 <= 0 || !self.data.money ) {
            app.com.toast('请填写金额');
            return false;
        }
        var postdata = {
            op:'jifenadd',
            money : self.data.money,
        };

        if( self.data.payed ) return false;
        self.data.payed = true;

        app.com.http('admin','POST',postdata,0,true,'','',function(res){
            if (!res.data.errno && res.data) {
                
                wx.requestPayment({
					'appId' : res.data.data.appId,
                    'timeStamp': res.data.data.timeStamp,
                    'nonceStr': res.data.data.nonceStr,
                    'package': res.data.data.package,
                    'signType': 'MD5',
                    'paySign': res.data.data.paySign,
                    'success': function (payres) {
                        if( payres.errMsg == 'requestPayment:ok' ){
                            app.com.toast('支付完成');
                            var pages = getCurrentPages();
                            var beforePage = pages[pages.length - 2];
                            beforePage.onLoad();
                        }
                    },
                    'fail': function (payres) {
                        
                    }
                });
                self.data.payed = false;
            }else{
                app.com.alert(res.data.message);
            }
            self.data.payed = false;
        });

    },
    money : function(e){
        this.setData({
            money : e.detail.value,
            geted : e.detail.value*this.data.params.shopjfper,
        })
    },
    location : function( e ){
        app.com.location( e );
    },
    otherapp : function( e ){
        app.com.otherapp( e );
    },
    navigateto : function( e ){
        app.com.navigateto( e,this.data.tid );
    },
    redirectto : function( e ){
        app.com.redirectto( e,this.data.tid );
    },    
    callphone : function(e){
        app.com.callphone( e );
    },
    showimages : function( e ){
        app.com.showimages( e );
    }
}))